﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace AutoInsurance
{
    public partial class newManager : System.Web.UI.Page
    {
        string strSqlConnection = "Data Source=localhost\\sqlexpress;Initial Catalog=AUTOINSURANCE;Integrated Security=True";
        private int role;
        

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string role = Session["role"].ToString();
                if (role == "5")
                {
                    Label2.Visible = true;
                    RadioButtonList1.Visible = true;
                    //CheckBox1.Visible = false;
                }
                else { }
            }
            catch (Exception ex)
            {
                Server.Transfer("Error.aspx?error=" + ex.Message);
            }

        }

        //добавляем нового менеджера
        protected void Button4_Click(object sender, EventArgs e)
        {
            try
            {
                role = 0;
                SqlConnection sqlCon = new SqlConnection(strSqlConnection);
                sqlCon.Open();

                if (RadioButtonList1.SelectedValue == "2")
                {
                    role = 5;
                }

                else if (RadioButtonList1.SelectedValue == "1")
                {
                    role = 2;
                }
                else
                {
                    role = 1;
                }
                SqlCommand newManager = new SqlCommand("insert into Manager (Password,Role,Name,Surname,Phone,Email,Login)" +
                    "VALUES ('" + TextBox4.Text + "','" + role + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + Convert.ToInt32(TextBox6.Text) + "','" + TextBox7.Text + "','" + TextBox3.Text + "')", sqlCon);
                newManager.ExecuteNonQuery();
                sqlCon.Close();
                Label1.Visible = true;
                TextBox1.Text = "";
                TextBox2.Text = "";
                TextBox3.Text = "";
                TextBox4.Text = "";
                //CheckBox1.Checked = false;
                TextBox6.Text = "";
                TextBox7.Text = "";
            }
            catch (Exception ex) {
                Server.Transfer("Error.aspx?error=" + ex.Message);
            }

        }

    }
}